﻿package view
{

	import flash.display.Stage;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;

	import org.puremvc.as3.patterns.mediator.Mediator;

	/**
	 * 媒介，主要用于监听用户在UI上触发的事件，然后传递消息给controller或proxy。
	 * 同时也负责向UI上呈现数据
	 * @author ...
	 */
	public class StageMediator extends Mediator
	{
		/**
		 * 
		 * @default 
		 */
		public static const NAME:String="STAGE_MEDIATOR";

		/**
		 * 
		 * @param viewComponent
		 */
		public function StageMediator(viewComponent:Stage)
		{
			//注册监听，从而获取UI上的事件
			viewComponent.addEventListener(MouseEvent.CLICK, mouseClick);
			
			viewComponent.addEventListener(KeyboardEvent.KEY_DOWN, keyboardClick);
		}

		/**
		 * 
		 * @param event
		 */
		private function mouseClick(event:MouseEvent):void
		{
			sendNotification(AllNotification.MOUSE_CLICK, event.localY);
			sendNotification(AllNotification.MOUSE_CLICK, event.localX);
		}

		private function keyboardClick(event:KeyboardEvent):void
		{
			sendNotification(AllNotification.KEY_CLICK, event.keyCode);
		}
	}
}
